﻿using Serilog;
using Serilog.Events;
using System;

namespace HDLogCenter.Infrastructure.Utils
{
    public static class LogHelper
    {
        public static void ConfigureLogging()
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Information()  // 设置最低日志级别为 Information，捕获所有高于该级别的日志
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information)  // 过滤 Information 级别
                    .WriteTo.File($"Logs/info-.txt", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning)  // 过滤 Warning 级别
                    .WriteTo.File($"Logs/warning-.txt", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error)  // 过滤 Error 级别
                    .WriteTo.File($"Logs/error-.txt", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Fatal)  // 过滤 Fatal 级别
                    .WriteTo.File($"Logs/fatal-.txt", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Verbose)  // 过滤 Verbose 级别
                    .WriteTo.File($"Logs/verbose-.txt", rollingInterval: RollingInterval.Day))
                .CreateLogger();
        }

        // 记录信息级别的日志
        public static void Info(string message)
        {
            Log.Information(message);
        }

        // 记录调试级别的日志
        public static void Debug(string message)
        {
            Log.Debug(message);
        }

        // 记录警告级别的日志
        public static void Warn(string message)
        {
            Log.Warning(message);
        }

        // 记录错误级别的日志
        public static void Error(string message)
        {
            Log.Error(message);
        }

        // 记录致命错误级别的日志
        public static void Fatal(string message)
        {
            Log.Fatal(message);
        }

        // 记录带异常的错误日志
        public static void Error(string message, Exception ex)
        {
            Log.Error(ex, message);
        }
    }
}

